------------------------------------------------------------------------------------------------------------------------------------
      name:  plog_18
       log:  /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/code/do/07_prepare_maps.log
  log type:  text
 opened on:  19 Sep 2022, 11:38:51

. *************************************************
. ********Prepare shapefile and maps data**********
. *************************************************
. 
. * directory definitions 
.         
.         project, doinfo
project PlaceBased_analysis > Project Name: PlaceBased_analysis
project PlaceBased_analysis > Project Dir.: /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication
project PlaceBased_analysis > Build start : 19sep2022, 11:38:37
project PlaceBased_analysis > Do-file Name: 07_prepare_maps.do
project PlaceBased_analysis > Enclosing do-files:
project PlaceBased_analysis >     PlaceBased_analysis.do

.         global pdir "`r(pdir)'"                                                 // the project's main dir.

.         global dofile "`r(dofile)'"                                             // do-file's stub name

.         global data_original = "$pdir/data_original"  //data directory for coded data 

.         global data_coded = "$pdir/data_coded"  //data directory for coded data 

.         global figures = "$pdir/results/figures"  //data directory for figures

.         global tables = "$pdir/results/tables"  //data directory for tables

. 
. * 
.         // report any data we create previously and we do need here: 
.         project, uses("$data_coded/placebased_regional.dta")
project PlaceBased_analysis > do-file uses: "data_coded/placebased_regional.dta" filesig(1029121884:16892740)

.         
. //
.         * get shapefile of Italy, prepare and merge with data from Campante     
.         project, relies_on("$data_original/Shapefile/Limiti_2016_ED50_g/Com2016_ED50_g/Com2016_ED50_g.shp")
project PlaceBased_analysis > do-file relies on: "data_original/Shapefile/Limiti_2016_ED50_g/Com2016_ED50_g/Com2016_ED50_g.shp" file
> sig(2681302914:14142956)

. 
.         shp2dta using "$data_original/Shapefile/Limiti_2016_ED50_g/Com2016_ED50_g/Com2016_ED50_g", database("$data_coded/itdb") co
> ordinates("$data_coded/itcoord") genid(id) gencentroids(coord)
type: 5

.         use "$data_coded/itdb", clear

.         
.         rename PRO_COM comune_id

.         
.         tempfile shapefile

.         save `shapefile'
file /var/folders/_2/rcg0d0g53jg5kxsfmp92khb99pbw__/T//S_88530.000004 saved as .dta format

.         
.         merge 1:1 comune_id using "$data_coded/placebased_regional.dta"
(variable id was int, now float to accommodate using data's values)
(variable comune_id was long, now double to accommodate using data's values)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                             7,998  (_merge==3)
    -----------------------------------------

.         drop _merge 

.         *
.         keep id x_coord y_coord COD_REG COD_CM COD_PRO comune_id km_to_ugs referendum_no

.         
.         gen ugs_yn = 1 if km_to_ugs == 0 
(7,674 missing values generated)

.         replace ugs_yn = 0 if km_to_ugs > 0
(7,674 real changes made)

.         
.         lab var km_to_ugs "distance to closest UGS (in km)"

.         lab var ugs_yn "UGS station (0,1)"

.         
.         save "$data_coded/placebased_mapdata.dta", replace
(file /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/data_coded/placebased_mapdata.dta not found)
file /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/data_coded/placebased_mapdata.dta saved

. 
. *
.         // also produce figure 2b: 
.         drop _all

.         import delimited "$data_coded/events_comune.csv", clear
(178 vars, 7,998 obs)

. 
.         *import meetup data, clear and save temporary
.         foreach w of varlist n_total-wn_posttreat {
  2.                 replace `w'="0" if `w'=="NA"
  3.                 destring `w', replace
  4.         }
(7,213 real changes made)
n_total: all characters numeric; replaced as int
(7,213 real changes made)
n_startto09: all characters numeric; replaced as int
(7,213 real changes made)
n_09to11: all characters numeric; replaced as int
(7,213 real changes made)
n_12to15: all characters numeric; replaced as int
(7,213 real changes made)
n_startto16: all characters numeric; replaced as int
(7,213 real changes made)
n_16: all characters numeric; replaced as int
(7,213 real changes made)
n_16toend: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_157d: all characters numeric; replaced as int
(7,213 real changes made)
n_pre_157d: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_24m: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_12m: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_6m: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_120d: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_90d: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_60d: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_30d: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_campaign: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_campaign_short: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_referendum: all characters numeric; replaced as int
(7,213 real changes made)
n_pre_120d: all characters numeric; replaced as int
(7,213 real changes made)
n_pre_90d: all characters numeric; replaced as int
(7,213 real changes made)
n_pre_60d: all characters numeric; replaced as int
(7,213 real changes made)
n_pre_30d: all characters numeric; replaced as int
(7,213 real changes made)
n_pre_campaign: all characters numeric; replaced as int
(7,213 real changes made)
n_total_renzi: all characters numeric; replaced as int
(7,213 real changes made)
n_total_ref: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_ref: all characters numeric; replaced as byte
(7,213 real changes made)
n_treat_renzi: all characters numeric; replaced as byte
(7,213 real changes made)
n_total_loc_outdoor: all characters numeric; replaced as int
(7,213 real changes made)
n_total_loc_indoor: all characters numeric; replaced as int
(7,213 real changes made)
n_total_loc_undefined: all characters numeric; replaced as int
(7,213 real changes made)
n_total_loc_missing: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_loc_outdoor: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_loc_indoor: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_loc_undefined: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_loc_missing: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_loc_outdoor_157d: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_loc_indoor_157d: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_loc_undefined_157d: all characters numeric; replaced as int
(7,213 real changes made)
n_treat_loc_missing_157d: all characters numeric; replaced as int
(7,213 real changes made)
n_pre_loc_outdoor_157d: all characters numeric; replaced as int
(7,213 real changes made)
n_pre_loc_indoor_157d: all characters numeric; replaced as int
(7,213 real changes made)
n_pre_loc_undefined_157d: all characters numeric; replaced as int
(7,213 real changes made)
n_pre_loc_missing_157d: all characters numeric; replaced as int
(7,213 real changes made)
n_posttreat: all characters numeric; replaced as int
(7,213 real changes made)
n_2005: all characters numeric; replaced as byte
(7,213 real changes made)
n_2006: all characters numeric; replaced as int
(7,213 real changes made)
n_2007: all characters numeric; replaced as int
(7,213 real changes made)
n_2008: all characters numeric; replaced as int
(7,213 real changes made)
n_2009: all characters numeric; replaced as int
(7,213 real changes made)
n_2010: all characters numeric; replaced as int
(7,213 real changes made)
n_2011: all characters numeric; replaced as int
(7,213 real changes made)
n_2012: all characters numeric; replaced as int
(7,213 real changes made)
n_2013: all characters numeric; replaced as int
(7,213 real changes made)
n_2014: all characters numeric; replaced as int
(7,213 real changes made)
n_2015: all characters numeric; replaced as int
(7,213 real changes made)
n_2016: all characters numeric; replaced as int
(7,213 real changes made)
n_2017: all characters numeric; replaced as int
(7,213 real changes made)
n_2018: all characters numeric; replaced as int
(7,213 real changes made)
n_ge13toge18: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m0_m3: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m3_end: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m0_m12: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m0_m1: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m1_m2: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m2_m3: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m3_m4: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m4_m5: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m5_m6: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m6_m7: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m7_m8: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m8_m9: all characters numeric; replaced as byte
(7,213 real changes made)
n_postref_m9_m10: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m10_m11: all characters numeric; replaced as int
(7,213 real changes made)
n_postref_m11_m12: all characters numeric; replaced as int
(7,213 real changes made)
wn_total: all characters numeric; replaced as long
(7,213 real changes made)
wn_startto09: all characters numeric; replaced as int
(7,213 real changes made)
wn_09to11: all characters numeric; replaced as int
(7,213 real changes made)
wn_12to15: all characters numeric; replaced as long
(7,213 real changes made)
wn_startto16: all characters numeric; replaced as long
(7,213 real changes made)
wn_16: all characters numeric; replaced as int
(7,213 real changes made)
wn_16toend: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_157d: all characters numeric; replaced as int
(7,213 real changes made)
wn_pre_157d: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_24m: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_12m: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_6m: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_120d: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_90d: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_60d: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_30d: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_campaign: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_campaign_short: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_referendum: all characters numeric; replaced as long
(7,213 real changes made)
wn_pre_120d: all characters numeric; replaced as int
(7,213 real changes made)
wn_pre_90d: all characters numeric; replaced as int
(7,213 real changes made)
wn_pre_60d: all characters numeric; replaced as int
(7,213 real changes made)
wn_pre_30d: all characters numeric; replaced as int
(7,213 real changes made)
wn_pre_campaign: all characters numeric; replaced as long
(7,213 real changes made)
wn_total_renzi: all characters numeric; replaced as int
(7,213 real changes made)
wn_total_ref: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_ref: all characters numeric; replaced as int
(7,213 real changes made)
wn_treat_renzi: all characters numeric; replaced as int
(7,213 real changes made)
wn_posttreat: all characters numeric; replaced as int

.         
.         foreach w of varlist n_total-wn_posttreat {
  2.                 gen log_`w'=log(`w'+1)
  3.         }

.         
.         *there are duplicate comunes in the data: 
.         duplicates tag comune_id, gen(dup)

Duplicates in terms of comune_id

.         
.         tempfile meetup

.         save `meetup'
file /var/folders/_2/rcg0d0g53jg5kxsfmp92khb99pbw__/T//S_88530.000005 saved as .dta format

. 
.         // open geocoded italy data: 
.         use "$data_coded/itdb.dta", clear 

. 
.         rename PRO_COM comune_id

.         
.         merge 1:1 comune_id using "`meetup'", gen(_merge_meetup)

    Result                      Number of obs
    -----------------------------------------
    Not matched                             0
    Matched                             7,998  (_merge_meetup==3)
    -----------------------------------------

. 
.         **
.         gen treated=0

.         replace treated=1 if n_total>=1
(785 real changes made)

. 
.         save "$data_coded/placebased_m5s_mapdata.dta", replace
(file /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/data_coded/placebased_m5s_mapdata.dta not found)
file /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/data_coded/placebased_m5s_mapdata.dta saved

. 
. * 
.         // report any data we create with this do file: 
.         project, creates("$data_coded/placebased_mapdata.dta")
project PlaceBased_analysis > do-file creates: "data_coded/placebased_mapdata.dta" filesig(331457870:323923)

.         project, creates("$data_coded/placebased_m5s_mapdata.dta")
project PlaceBased_analysis > do-file creates: "data_coded/placebased_m5s_mapdata.dta" filesig(1886122966:9241796)

.         project, creates("$data_coded/itdb.dta")
project PlaceBased_analysis > do-file creates: "data_coded/itdb.dta" filesig(1368692780:792039)

.         project, creates("$data_coded/itcoord.dta")
project PlaceBased_analysis > do-file creates: "data_coded/itcoord.dta" filesig(3580147049:15566481)

. 
. 
. 
.         
. 
end of do-file
      name:  plog_18
       log:  /Users/au660280/Dropbox/m5S/JoP_PlaceBasedCampaigning_replication/code/do/07_prepare_maps.log
  log type:  text
 closed on:  19 Sep 2022, 11:38:55
------------------------------------------------------------------------------------------------------------------------------------
